package cn.edu.neusoft.yuejian4.yuejian_4.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.yuejian4.yuejian_4.Config.Server;
import cn.edu.neusoft.yuejian4.yuejian_4.R;
import cn.edu.neusoft.yuejian4.yuejian_4.javaBean.ShowComment;

/**
 * Created by Lix on 2018/10/15.
 */

public class ShowCommentAdapter extends  RecyclerView.Adapter<ShowCommentAdapter.ViewHolder> {

    private List<ShowComment> mShowComment;
    private Context mContext;

    public ShowCommentAdapter(Context mContext, List<ShowComment> mShowComment){
        this.mContext = mContext;
        this.mShowComment = mShowComment;
        //mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public ShowCommentAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.show_comment_cardview,parent,false);
        ShowCommentAdapter.ViewHolder holder = new ShowCommentAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ShowCommentAdapter.ViewHolder holder, int position) {

        final ShowComment showComment = mShowComment.get(position);
        Picasso.with(mContext)
                .load(Server.PIC_URL_J+showComment.getUser_pic())
                .placeholder(R.drawable.ic_default_img)
                .memoryPolicy(MemoryPolicy.NO_CACHE)
                .into(holder.comm_user_img);

        holder.comm_user_name.setText(showComment.getUser_name()+":");
        holder.comm_intro.setText(showComment.getIntro());
        holder.comm_time.setText(showComment.getTime());

    }

    @Override
    public int getItemCount() {
        return mShowComment.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        ImageView comm_user_img;
        TextView comm_user_name,comm_intro,comm_time;
        public ViewHolder(View view){
            super(view);
            comm_user_img= (ImageView)view.findViewById(R.id.show_comment_user_img);
            comm_user_name = (TextView)view.findViewById(R.id.show_comment_user_name);
            comm_intro = (TextView)view.findViewById(R.id.show_comment_intro);
            comm_time = (TextView)view.findViewById(R.id.show_comment_time);

        }
    }
}
